<script type="text/javascript" src="/kkpager/kkpager.js"></script>
<script type="text/javascript" src="/js/adm/vb-kkpager.js"></script>
<h1 class="page_title">作业管理</h1>
<span class="btn-upload form-group">
        <input class="input-text" type="text" id="keyword"
               <#if keyword??>
                   value="${keyword}"
               </#if>
               style="width:200px" placeholder="VB综测题3">
        <a href="javascript:research('/adm/project','作业管理');" class="btn btn-primary upload-btn"><i class="Hui-iconfont">&#xe665;</i> 搜 索</a>
    </span>
<input class="btn btn-primary radius" type="button" value="添 加"
       style="float: right;margin-bottom: 15px;" id="addBtn">
<#if pageBean.content?size != 0>
<table class="table table-border table-bordered table-hover">

    <thead>
    <tr>
        <th>作业名称</th>
        <th>作业类型</th>
        <th>发布时间</th>
        <th>当前提交人数</th>
        <th>作业状态</th>
        <th>最大提交次数</th>
        <th style="width: 16%">操 作</th>
    </tr>
    </thead>
    <tbody>
    <#list pageBean.content as bean>
        <tr>
            <td><input class="input-text" id="project${bean.projectId}"
                       readonly="readonly" disabled value="${bean.projectName}"></td>
            <td>
                <#if bean.classification == "0">
                    实例题
                    <#else>
                    设计题
                </#if>
            </td>
            <td>${bean.upTime}</td>
            <td>${bean.num!'0'}人</td>
            <#if bean.status == "1">
                <td style="color: blue">
                    可提交
                </td>
            <#else>
                <td style="color: red">
                    不可提交
                </td>
            </#if>
            <td>
                ${bean.upTimesMax}次
            </td>
            <td>
                <input class="btn btn-secondary radius" type="button" value="详 情"
                       onclick="selectProject(${bean.projectId})">
                <input class="btn btn-warning radius" type="button" value="修改名称"
                       onclick="editProject(${bean.projectId}, this)">
            </td>
        </tr>
    </#list>
    <#else>
        <div class="text-c" style="height: 300px;"><h3>无记录.</h3></div>
    </#if>
    <tr>
        <td colspan="7">
            <div id="kkpager"></div>
        </td>
    </tr>
    </tbody>
    <tfoot>
    </tfoot>
</table>
<script>
    var changeView = function(n) {
        selectView("/adm/project/?pageNum=" + n + "&keyword=" + "${keyword!''}", "班级详情");
    };
    $('#addBtn').on('click', function () {
        selectView("/adm/project/add", "添加VB作业");
    });
    var selectProject = function (id) {
        selectView("/adm/project/" + id, "班级详情");
    };

    var editProject = function (id, btn) {
        var editInput = $("#project" + id);
        editInput.removeAttr("readonly");
        editInput.removeAttr("disabled");
        $(btn).val("确认修改");
        $(btn).attr("onclick", "confirmEdit(" + id + ", this)");
    };
    var confirmEdit = function (id, btn) {
        var editInput = $("#project" + id);
        if ('' === editInput.val().trim()) {
            alert("班级名称不能为空");
            return;
        }
        stupidAjaxGetJson(
            '/adm/project/' + id,
            "PUT",
            {projectName: editInput.val()},
            function (data) {
                if (!data.success) {
                    alert(data.msg);
                } else {
                    alert(data.msg);
                    editInput.attr("readonly", "readonly");
                    editInput.attr("disabled", "disabled");
                    $(btn).val("修改名称");
                    $(btn).attr("onclick", "editProject(" + id + ", this)");
                }
            }
        );
    };
</script>
<script type="text/javascript">
    generateKK(${pageBean.pageNum}, ${pageBean.pageCount}, ${pageBean.rowCount});
</script>